/**
 * 楼盘详情
 */
import React, { Component } from 'react'
import Navbar from '@components/navbar'
import {httpGetMyData112} from '@api/common'
import { Card,Toast } from 'antd-mobile'


export default  class app extends Component {
  constructor(props) {
    super(props)
    this.state = {
      // 加载.
      loading:false,
      // 列表数据
      listData:[],
      // 楼盘id
      lpid:props.match.params.lpid,
    }
    // 请求参数
    this.requestParams = {
      projectId:props.match.params.lpid,
      type:1,
    }
  }

  componentDidMount(){
    this.getListData()
  }

  getListData=()=>{
    const reqData = {
      ...this.requestParams,
    }
    Toast.loading('正在加载数据...',0)
    httpGetMyData112(reqData,res=>{
      let {listData} = this.state
      Toast.hide()
      listData = res.reverse()
      this.setState({
        listData,
      })
    })
  }

  /**
   * 点击楼盘，查看楼盘详情
   */
  onClickLP=(item,i,value)=>{
    let BUILDIDs = item.BUILDID
    BUILDIDs = BUILDIDs.split(',')
    if(BUILDIDs[i]){
      console.log(BUILDIDs[i],value)
      this.props.history.push(`/app/lpb/${BUILDIDs[i]}/${value}`)
    }
  }

  render() {
    const {listData} = this.state
    return (
      <div className="app-wrap">
        <Navbar title="楼盘详情" left="back"/>
        <div className="app-content">
          {
            listData.map((item,index)=>{
              const result = (
                <Card key={index}>
                  <Card.Header
                    title={<div onClick={()=>this.onClickLP(item)}>{`${index+1}：${item.F_PROJECT_NAME}`}</div>}
                    extra={<span>所属区县：{item.F_SITE}</span>}
                  />
                  <Card.Body>
                    <div className="card-body-item"><span>项目所在地：</span><span>{item.F_ADDR}</span></div>
                    <div className="card-body-item"><span>企业名称：</span><span>{item.F_ENTERPRISE_NAME}</span></div>
                    <div className="card-body-item"><span>预售许可证号：</span><span>{item.F_PRESALE_CERT}</span></div>
                    <div className="card-body-item">
                      <span>楼栋：</span>
                      <span>{
                        item.F_BLOCK.split(',').map((v,i)=>(<a key={i} className="link" onClick={()=>this.onClickLP(item,i,v)}>{v}</a>))
                      }</span>
                    </div>
                    <div className="card-body-item"><span>注册日期：</span><span>{item.F_REGISTER_DATE}</span></div>
                    <div className="card-body-item"><span>楼盘名称：</span><span>{item.F_PROJECT_NAME}</span></div>
                    <div className="card-body-item"><span>可售住宅套数：</span><span>{item.KSZZNUM}</span></div>
                    <div className="card-body-item"><span>可售非住宅件数：</span><span>{item.KSFZZNUM}</span></div>
                    <div className="card-body-item"><span>建筑ID：</span><span>{item.BUILDID}</span></div>
                  </Card.Body>
                  <Card.Footer content="类别" extra={<div>{item.F_LB}</div>} />
                </Card>
              )
              return result
            })
          }
        </div>
      </div>
    )
  }
}
